package servlet;

import bean.User;
import service.impl.UserServiceImpl;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
@WebServlet("/admin/admin_modify_userinfo")
public class AdminModifyUserInfo extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

    }

    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        request.setCharacterEncoding("UTF-8"); // 设置请求编码为UTF-8
        response.setContentType("text/html;charset=UTF-8"); // 设置响应内容类型和编码
        String userIdStr = request.getParameter("userId");
        int userId = Integer.parseInt(userIdStr);
        String nameStr = request.getParameter("name");
        System.out.println(nameStr);
        String passwordStr = request.getParameter("password");
        String mobileStr = request.getParameter("mobile");
        User user = new User();
        user.setMobile(mobileStr);
        user.setName(nameStr);
        user.setPassword(passwordStr);
        user.setId(userId);
        new UserServiceImpl().updateUser(user);
    }
}
